#include "stdafx.h"
#include "XTextEnvImpl.h"

#include "UIDefaultValue.h"

IMPLEMENT_SKIN_CLASS(CXTextEnvImpl);


CXTextEnvImpl::CXTextEnvImpl()
{
    m_clrText       = XDEFAULT_TEXT_COLOR;
    m_clrTextBk     = XDEFAULT_TEXT_BACK_COLOR;
    m_bTransparent  = XDEFAULT_TEXT_TRANSPARENT;
    m_dwDrawFlags   = XDEFAULT_DRAW_FLAGS;
}

CXTextEnvImpl::~CXTextEnvImpl()
{
    ;
}

//////////////////////////////////////////////////////////////////////////
// IXDrawContextObj
void CXTextEnvImpl::SetupCanvas(XCANVAS canvas)
{
    m_clrOldText        = SetTextColor((HDC)canvas, m_clrText);
    m_clrOldTextBk      = SetBkColor((HDC)canvas, m_clrTextBk);
    m_bOldTransparent   = (SetBkMode((HDC)canvas, m_bTransparent ? TRANSPARENT : OPAQUE) == TRANSPARENT);
}

void CXTextEnvImpl::RestoreCanvas(XCANVAS canvas)
{
    SetTextColor((HDC)canvas, m_clrOldText);
    SetBkColor((HDC)canvas, m_clrOldTextBk);
    SetBkMode((HDC)canvas, m_bOldTransparent ? TRANSPARENT : OPAQUE);
}

XHANDLE CXTextEnvImpl::get_DrawObj()
{
    return NULL;
}

//////////////////////////////////////////////////////////////////////////
// IXTextEnv
void CXTextEnvImpl::put_TextColor(COLORREF clrText)
{
    m_clrText = clrText;
}

void CXTextEnvImpl::put_BackColor(COLORREF clrBkText)
{
    m_clrTextBk = clrBkText;
}

void CXTextEnvImpl::put_Transparent(BOOL bTrans)
{
    m_bTransparent = bTrans;
}

void CXTextEnvImpl::put_DrawFlags(DWORD dwFlags)
{
    m_dwDrawFlags = dwFlags;
}

COLORREF CXTextEnvImpl::get_TextColor()
{
    return m_clrText;
}

COLORREF CXTextEnvImpl::get_BkColor()
{
    return m_clrTextBk;
}

BOOL     CXTextEnvImpl::get_Transparent()
{
    return m_bTransparent;
}

DWORD    CXTextEnvImpl::get_DrawFlags()
{
    return m_dwDrawFlags;
}

void CXTextEnvImpl::put_Singleline(IN BOOL bSingleline)
{
    if(bSingleline)
    {
        m_dwDrawFlags = m_dwDrawFlags & (~DT_EDITCONTROL);
        m_dwDrawFlags = m_dwDrawFlags & (~DT_WORDBREAK);
        m_dwDrawFlags |= DT_SINGLELINE;
    }
    else
    {
        m_dwDrawFlags = m_dwDrawFlags & (~DT_SINGLELINE);
        m_dwDrawFlags |= DT_EDITCONTROL | DT_WORDBREAK;
    }
}

BOOL CXTextEnvImpl::get_Singleline()
{
    return ((m_dwDrawFlags & DT_SINGLELINE) == DT_SINGLELINE);
}
